package com.zhentao.controller;


import com.zhentao.aop.MyLog;
import com.zhentao.domain.SUpdateQuestion;
import com.zhentao.domain.dto.SUpdateQuestionDto;
import com.zhentao.result.Result;
import com.zhentao.service.SUpdateQuestionService;
import com.zhentao.service.impl.SUpdateQuestionServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

@RestController
@RequestMapping("/question")
@Api(value = "申请修改题目")
public class QuestionController {

    @Resource
    public SUpdateQuestionService sUpdateQuestionService;


    //老师提交申请修改题目
    @PostMapping("/submitApplication")
    @MyLog(title = "题目管理",content = "提交修改题目申请")
    public Result submitApplication(@RequestBody SUpdateQuestion sUpdateQuestion){
        return sUpdateQuestionService.submitApplication(sUpdateQuestion);
    }

    //根据老师的id查看对应的申请修改题目信息
    @PostMapping("/getUpdateQuestionById")
    @MyLog(title = "题目管理",content = "查看修改题目申请")
    public Result getUpdateQuestionById(@RequestBody SUpdateQuestionDto sUpdateQuestion){
        return sUpdateQuestionService.getUpdateQuestionById(sUpdateQuestion);
    }

    //管理员通过提交的申请
    @PostMapping("/passApplication/{id}")
    @MyLog(title = "题目管理",content = "通过修改题目申请")
    public Result passApplication(@PathVariable("id") Integer id){
        return sUpdateQuestionService.passApplication(id);
    }


    //管理员驳回提交的修改申请
    @PostMapping("/rejectApplication/{id}/{cause}")
    @MyLog(title = "题目管理",content = "驳回修改题目申请")
    public Result rejectApplication(@PathVariable("id") Integer id,@PathVariable("cause") String cause){
        return sUpdateQuestionService.rejectApplication(id,cause);
    }

    //管理员查看所有的修改申请记录
    @PostMapping("/getAllUpdateQuestion")
    @MyLog(title = "题目管理",content = "查看所有修改题目申请")
    public Result getAllUpdateQuestion(@RequestBody SUpdateQuestionDto dto) {
        return sUpdateQuestionService.getAllUpdateQuestion(dto);
    }


    //删除申请修改记录信息
    @PostMapping("/deleteUpdateQuestion")
    @MyLog(title = "题目管理",content = "删除修改题目申请")
    public Result deleteUpdateQuestion(@RequestBody Integer[] id){
        return Result.OK(this.sUpdateQuestionService.removeBatchByIds(Arrays.asList(id)));
    }
}
